//
//  RenewChooseCityCell.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2018/12/19.
//  Copyright © 2018年 HCreater. All rights reserved.
//

#import "RenewChooseCityCell.h"

@interface RenewChooseCityCell ()

/// viewModle
@property (nonatomic, readwrite, strong) RenewChooseCityCellModel *viewModel;

/// IBOutlet
@property (weak, nonatomic) IBOutlet UILabel* cityLabel;
@property (weak, nonatomic) IBOutlet UILabel* perLabel;
@property (weak, nonatomic) IBOutlet UIButton* chooseBtn;
@property (weak, nonatomic) IBOutlet UIButton* closeBtn;

@end

@implementation RenewChooseCityCell

- (void)awakeFromNib
{
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

#pragma mark - bind data
- (void)bindViewModel:(RenewChooseCityCellModel *)viewModel
{
    self.viewModel = viewModel;
    
    @weakify(self);
    
    self.cityLabel.text = self.viewModel.cityName;
//    self.perLabel.text = self.viewModel.subcontent;
    
    [[RACObserve(self.viewModel, isChoose) distinctUntilChanged] subscribeNext:^(id x)
    {
        @strongify(self);
        
        self.chooseBtn.selected = self.viewModel.isChoose;
    }];
    
    [[self.closeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x)
     {
         @strongify(self);
         
         [self.viewModel.closeCommand execute:nil];
     }];
}

@end
